package data.set.adaptator;

import java.util.Iterator;

import tools.Pair;

import data.set.OfflineSet;
import data.set.OfflineSetIterator;


/**
 * This class is used to build aset of pairs using to sets
 * @author denoyer
 *
 * @param <X>
 * @param <Y>
 */

public class TwoOfflineSet_To_PairOfflineSet<X,Y> implements OfflineSet<Pair<X,Y>>
{
	private OfflineSet<X> setx;
	private OfflineSet<Y> sety;
	
	
	
	public TwoOfflineSet_To_PairOfflineSet(OfflineSet<X> setx,OfflineSet<Y> sety)
	{
		super();
		this.setx = setx;
		this.sety = sety;
	}

	
	public Pair<X, Y> getObject(int id) {
		return new Pair<X,Y>(setx.getObject(id),sety.getObject(id));
	}

	
	public OfflineSetIterator<Pair<X, Y>> inputsetiterator() {
		return(new IT(setx.inputsetiterator()));
	}

	
	public long size() {
		return setx.size();
	}

	
	public Iterator<Pair<X, Y>> iterator() {
		return(new Iterator_FromOfflineSetIterator<Pair<X,Y>>(inputsetiterator()));
	}
	
	public class IT implements OfflineSetIterator<Pair<X,Y>>
	{
		private OfflineSetIterator<X> it;
		
		public IT(OfflineSetIterator<X> it)
		{
			this.it=it;
		}
		
		
		public int getCurrentId() 
		{
			return(it.getCurrentId());
		}

		
		public Pair<X, Y> getCurrentObject() 
		{
			return new Pair<X,Y>(it.getCurrentObject(),sety.getObject(it.getCurrentId()));
		}

		
		public boolean hasNext() {
			return(it.hasNext());
		}

		
		public void next() 
		{
			it.next();
		}
	
	}	
}
